<template>
    <view class="container">
        <view class="content">
            <view class="input-group">
                <view class="input-row border">
                    <text class="title">{{coin}}数量：</text>
                    <m-input class="m-input" type="text" clearable focus v-model="coinNumber" placeholder="请输入购买数量"></m-input>
                </view>
				<!-- <view class="input-row border">
				    <text class="title">购买金额：</text>
				    <m-input class="m-input" type="text" disabled clearable v-model="coinMoney" placeholder="请输入购买金额"></m-input>
				</view> -->
            </view>
			
            <view class="btn-row">
                <button type="primary" class="primary" @tap="buy">购买</button>
            </view>
            
        </view>
    </view>
</template>

<script>
    import service from '../../../service.js';
	import network from '../../../common/network.js';
	import validator from '../../../common/validator.js';
	import sha1 from 'crypto-js/sha1.js'

    import {
        mapState,
        mapMutations
    } from 'vuex'
    import mInput from '../../../components/m-input.vue'

    export default {
        components: {
            mInput
        },
		data() {
            return {
                coinNumber: '',
                coinMoney: '',
				coin: '',
                positionTop: 0
            }
        },
        onLoad(option) { //option为object类型，会序列化上个页面传递的参数
        	this.coin = option.coin;
        },
		computed: {
			...mapState(['hasLogin', 'user'])
		},
        methods: {
            buy() {
                const self = this;
				const business_id = this.user.id;
                network.requestJsonRpc("/jsonrpc/", 'POST', {
                		"id": 1,
                		"method": "balance.update",
                		"params": [this.user.id, this.coin, "deposit", business_id, this.coinNumber, {}]
                	},
                	function(res) {
                		console.log("查询成功后:" + JSON.stringify(res));
                
                		uni.showToast({
                		    icon: 'none',
                		    title: '充值成功!'
                		});
                	});
            }
        }
    }
</script>

<style>
@import '../../../common/custom.css';

</style>
